package com.yzc.mihuyou.controller;

import com.alibaba.fastjson.JSONObject;
import com.yzc.mihuyou.entity.MessageBody;
import com.yzc.mihuyou.vo.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/mihuyou/ping")
public class MessageBodyController {

    @Autowired
    StringRedisTemplate stringRedisTemplate;

    @GetMapping("port/{id}/{Aid}")
    public JsonResult jsonResult(@PathVariable("id") Long id,@PathVariable("Aid") Long Aid){

        String key=id+","+Aid;
        if(!stringRedisTemplate.opsForHash().hasKey("userIDs", key)){
            key=Aid+","+id;
            if(!stringRedisTemplate.opsForHash().hasKey("userIDs", key)){
                return new JsonResult(201,"未存在");
            }
        }
        String sjw= (String) stringRedisTemplate.opsForHash().get("userIDs",key);
        List<MessageBody> list= JSONObject.parseArray(sjw, com.yzc.mihuyou.entity.MessageBody.class);

        Map<String,Object> map=new HashMap<>();
        map.put("pinst",list);

        return   new JsonResult(200,"查询成功",map);
    }
}
